Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use array_values so params are still passed to scope #387

Merged
merged 1 commit into from
Jan 22, 2020

Conversation

jamesburrow23
Copy link
Contributor

@jamesburrow23 jamesburrow23 commented Nov 25, 2019

Currently any filters that are using associative keys cannot be passed to the scope using the splat operator.

Scenario

suppose I have this scope on my model:

public function scopePublishedBetween($query, $start, $end)
    {
        return $query
            ->where('published_at', '>=', Carbon::parse($start))
            ->where('published_at', '<=', Carbon::parse($end));
    }

And I've allowed this scope in my query:

AllowedFilter::scope('published_between')

Now I pass my date range as an associative array in the request like so:

let params = {
    filter: {
        start: '2019-11-20',
        end: '2019-11-25',
    },
};

When the query builder executes this request I receive this error because the splat operator does not support unpacking associative arrays.

Symfony\Component\Debug\Exception\FatalThrowableError
Cannot unpack array with string keys

@AlexVanderbist
Copy link
Member

Great, thanks!

@AlexVanderbist AlexVanderbist merged commit 1e7044d into spatie:master Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants